
#ifndef  SIMPLEAPPENDER_H
#define  SIMPLEAPPENDER_H

#include <utility>
#include <string>
#include <memory>
#include "recovery/Status.h"

class Topic;

namespace recovery {
namespace fs {
namespace file {
	class FileAppender;
}
}
}

class SimpleAppender {
public:
    SimpleAppender(Topic & topic);
    ~SimpleAppender() ;

    bool open() ;
    bool close() ;

    std::pair<recovery::Status, size_t> append(const std::string & data);
	recovery::Status commit();

protected:
    void updateFileSize();
    void recordAppendedBytes(const size_t appendedBytes);

private:
    Topic &  _topic;//meta info from out scope
    size_t _appendedBytes = 0;
    std::unique_ptr<recovery::fs::file::FileAppender> _log;
};

#endif   /* SIMPLEAPPENDER_H */
